package com.fancy.recommendation.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fancy.recommendation.entity.UserBehavior;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 用户行为Mapper
 *
 * @author fancy
 */
@Mapper
public interface UserBehaviorMapper extends BaseMapper<UserBehavior> {

    /**
     * 获取用户行为统计
     */
    List<Map<String, Object>> getUserBehaviorStats(@Param("userId") Long userId);

    /**
     * 获取用户最近行为
     */
    List<UserBehavior> getRecentBehaviors(@Param("userId") Long userId, @Param("limit") Integer limit);

    /**
     * 获取热门内容
     */
    List<Map<String, Object>> getHotContentByAction(@Param("actionType") String actionType,
                                                   @Param("startTime") LocalDateTime startTime,
                                                   @Param("limit") Integer limit);

    /**
     * 清理过期行为数据
     */
    int deleteExpiredBehaviors(@Param("expireTime") LocalDateTime expireTime);

    /**
     * 获取用户对特定目标的行为
     */
    List<UserBehavior> getUserTargetBehaviors(@Param("userId") Long userId,
                                            @Param("targetId") Long targetId,
                                            @Param("targetType") String targetType);

    /**
     * 获取相似用户行为
     */
    List<Map<String, Object>> getSimilarUserBehaviors(@Param("userId") Long userId,
                                                     @Param("targetIds") List<Long> targetIds,
                                                     @Param("minCommonBehaviors") Integer minCommonBehaviors,
                                                     @Param("limit") Integer limit);

    /**
     * 批量插入用户行为
     */
    int batchInsertBehaviors(@Param("behaviors") List<UserBehavior> behaviors);
}
